﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LGE;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace EggCatcher
{
    class Chicken : GameObject
    {
        float eggDropRate = .3f;
        float poopDropRate = .1f;
        const float pauseTime = .5F;
        double pauseTimer = 0;
        SpriteSheet spriteSheet;

        public Chicken(GameScreen gs)
            : base(gs, Engine.Load<Texture2D>("Images\\chicken"))
        {
            spriteSheet = new SpriteSheet(this, 11, 600/11);
        }

        public override void Update(GameTime gameTime)
        {
            UpdateSprite(gameTime);
            UpdateDrop(gameTime);
        
        }

        public void UpdateDrop(GameTime gameTime)
        {
            if (pauseTimer > 0) pauseTimer -= gameTime.ElapsedGameTime.TotalSeconds;
            else
            {
                if (Rand.Next(100) < eggDropRate * 100 / 60)
                {
                    spriteSheet.completed = false;
                    (gameScreen as PlayScreen).egg.Add(new Egg(gameScreen, position));
                    pauseTimer = pauseTime;
                }
                else if (Rand.Next(100) < poopDropRate * 100 / 60)
                {
                    spriteSheet.completed = false;
                    (gameScreen as PlayScreen).poop.Add(new Poop(gameScreen, position));
                    pauseTimer = pauseTime;
                }
            }
        }

        public void UpdateSprite(GameTime gameTime)
        {
            if (!spriteSheet.completed) spriteSheet.Update(gameTime);
        }
    }
}